<?php 

class Car
{
    protected $brand;
    private $no;
    public $wheels = 4;

    public static $WHEELS = 4;

    public function getBrand()
    {
        return $this->brand;
    }

    public function setBrand($brand) : void
    {
        $this->brand = $brand;
    }

    public function __sleep()
    {
        return ['brand', 'no', 'wheels'];
    }

    public function __wakeup()
    {
        $this->no = 10001;
    }

    public function getNo()
    {
        return $this->no;
    }
}

$car = new Car();
$car->setBrand('领克01');

//将对象序列化为字符串后保存到文件
$string = serialize($car);
file_put_contents("car", $string);

//从文件反序列化
$content = file_get_contents("car");
$object = unserialize($content);
var_dump($object->getBrand());
var_dump("汽车品牌：" . $object->getBrand() . '<br/>') ;

echo "汽车No.:" . $object->getNo() . '<br/>';
echo "汽车轮子：" . $object->wheels . '<br/>';
